package com.sxz.sbs.module.mine;

import android.text.TextUtils;
import android.widget.ImageView;

import com.sxz.sbs.R;
import com.sxz.sbs.app.App;
import com.sxz.sbs.app.GlideApp;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.http.retrofit.HttpParamMap;
import com.sxz.sbs.module.mine.mode.SystemFileMode;
import com.sxz.sbs.module.mine.presenter.PaymentCodePresenter;
import com.sxz.sbs.module.mine.view.PaymentCodeView;
import com.sxz.sbs.widget.CommonTitle;

import java.util.HashMap;

import butterknife.BindView;

/**
 * @author hp
 * @date 2018/1/8
 * 收款码界面
 */

public class PaymentCodeActivity extends BaseActivity<PaymentCodePresenter> implements PaymentCodeView{
    @BindView(R.id.pay_qr_code)
    ImageView ivPayCode;
    @Override
    protected void init() {
       new CommonTitle.Builder(this).setTitle("收款码").build().show();
        HashMap<String,Object> map = HttpParamMap.getParamMap();
        map.put("fileType",2);
        mPresenter.getPayCode(map);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_paymentcode;
    }

    @Override
    protected PaymentCodePresenter createPresenter() {
        return new PaymentCodePresenter();
    }

    @Override
    public void showError(int errorTag, String msg) {
        if (!TextUtils.isEmpty(App.preferences.getValue("payment_code"))) {
            GlideApp.with(this).load(App.preferences.getValue("payment_code")).into(ivPayCode);
        } else {
            super.showError(errorTag, msg);
        }

    }

    @Override
    public void onGetPaymentCodeSuccess(SystemFileMode data) {
        if (mIsLive && data != null) {
            App.preferences.setValue("payment_code",data.getTxt_FileUrl());
            GlideApp.with(this).load(data.getTxt_FileUrl()).into(ivPayCode);
        }
    }
}
